package RecursiveSearcher;

import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;

/**
 * @ClassName LC78
 * @Description 子集
 * @Author ZJX
 * @Date 2024/9/17 18:10
 * @Version 1.0
 */
//   https://leetcode.cn/problems/subsets/description/

public class LC78 {
    List<List<Integer>> ret;
    List<Integer> path;

    public List<List<Integer>> subsets(int[] nums) {
        ret = new ArrayList<>();
        path = new ArrayList<>();

        dfs(nums,0);

        return ret;
    }

//    [1,2,3]
    private void dfs(int[] nums, int pos) {
       ret.add(new ArrayList<>(path));
        for (int i = pos; i < nums.length; i++) {
            path.add(nums[i]);
            dfs(nums,i+1);
//            恢复现场
            path.remove(path.size()-1);
        }
    }

    public static void main(String[] args) {
        LC78 lc78 = new LC78();
        int[] nums = {1,2,3};
        lc78.subsets(nums);
        System.out.println();
    }
}
